#ifndef _SHAPE_HH_
#define _SHAPE_HH_

#include <stdlib.h>
#include <time.h>

#include <vector>
#include "boost/smart_ptr.hpp"

#include "cxcore.h"

#include "basic_utils.hh"
#include "PDModel.hh"



class Shape{

public:

    Shape(bool robust = false, bool use_kalman = false){ m_robust = robust; m_kalman = use_kalman;}


    //use robust estimators when obtaining the coefficients in set_shape().
    bool set_robust(bool robust){
	bool k = m_robust; 
	m_robust = robust; 
	return k;}


    bool use_kalman(bool kalman);

    PDModel model;

    boost::shared_ptr<CvMat> get_shape();
    /** 
     * Set the shape
     * 
     * @param mat A 2xN matrix
     * @param override_size_check If true, the matrix \a mat may have
     * a different number of columns than the current matrix.
     */
    void set_shape(const CvMat *mat, bool override_size_check = false);

    //any of the parameters can be NULL.
    void set_coefficients(const CvMat *c, const CvMat *st);

    void get_coefficients(CvMat *c, CvMat *st);
    //initialize coefficient matrices, and reset them to zero
    void init_coefficients();
//     CvPoint origin;

//    ~Shape(){cvReleaseMat(&coeff);}


private:
    bool m_robust, m_kalman;
    boost::shared_ptr<CvMat> m_shape;
    boost::shared_ptr<CvMat> coeff, st_coeff;    
    boost::shared_ptr<CvKalman> m_kfilter;
    
    void init_kalman(void);

    void impose_parameter_limits(CvMat *c);
};

#endif
